package com.bodu.system.controller;

import com.bodu.core.common.AbstractCommonController;
import com.bodu.core.entity.ParamReq;
import com.bodu.core.entity.result.PageResult;
import com.bodu.core.entity.result.Result;
import com.bodu.global.annon.TraceLog;
import com.bodu.global.security.LoginUserUtil;
import com.bodu.system.entity.po.StorageConfigPo;
import com.bodu.system.entity.request.StorageConfigRequest;
import com.bodu.system.entity.vo.StorageConfigVo;
import com.bodu.system.service.StorageConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 存储配置 API
 *
 * @author Administrator
 */
@Api(tags = "存储配置 API")
@RestController
@RequestMapping("/storageConfig")
public class StorageConfigController extends AbstractCommonController<StorageConfigService, StorageConfigRequest, StorageConfigVo> {

    private final StorageConfigService storageConfigService;

    public StorageConfigController(StorageConfigService storageConfigService) {
        this.storageConfigService = storageConfigService;
    }

    @TraceLog()
    @ApiOperation("详情")
    @GetMapping("{id}")
    public Result getModel(@PathVariable("id") Long id) {
        return super.getModel(storageConfigService, id);
    }

    @TraceLog()
    @PostMapping
    @ApiOperation("保存存储配置")
    public Result<Integer> save(@RequestBody StorageConfigRequest request) {
        request.setCreateUser(LoginUserUtil.getUserId());
        return super.save(storageConfigService, request);
    }

    @TraceLog()
    @PutMapping
    @ApiOperation("更新存储配置")
    public Result<Integer> update(@RequestBody StorageConfigRequest request) {
        request.setCreateUser(LoginUserUtil.getUserId());
        return super.update(storageConfigService, request);
    }

    @TraceLog()
    @PostMapping("listPage")
    @ApiOperation("存储配置-查询")
    public Result<List<StorageConfigPo>> listPage(@RequestBody ParamReq req) {
        return super.listPage(storageConfigService, req);
    }

    @TraceLog()
    @PostMapping("countPage")
    @ApiOperation("存储配置-统计")
    public Result<Integer> countPage(@RequestBody ParamReq req) {
        return super.countPage(storageConfigService, req);
    }

    @TraceLog()
    @PostMapping("page")
    @ApiOperation("存储配置-分页数据")
    public Result<PageResult> page(@RequestBody ParamReq<StorageConfigRequest> req) {
        return super.page(storageConfigService, req);
    }

    @TraceLog()
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除存储配置")
    public Result<Integer> delete(@PathVariable("id") Long id) {
        return super.delete(storageConfigService, id);
    }

    @TraceLog()
    @ApiOperation("批量删除存储配置")
    @DeleteMapping("{ids}")
    public Result<Integer> batchDelete(List<Long> ids) {
        return super.batchDelete(storageConfigService, ids);
    }

    @TraceLog()
    /**
     * 存储状态只能存在一个起作用
     * @return
     */
    @ApiOperation("切换存储状态")
    @PostMapping("/switchStatus")
    public Result<Integer> switchStatus(@RequestBody StorageConfigRequest request){
        return storageConfigService.switchStatus(request);
    }

    @Override
    public Long getLoginUserId() {
        return LoginUserUtil.getUserId();
    }

}
